/**
Application: login page ,login form
Author:chilei
Date:2012/11/28
*/
//load tips
Ext.QuickTips.init();

Ext.namespace("clNameSpace");

//main app
clNameSpace.login = function(){

};

//
Ext.extend(clNameSpace.login,Ext.util.Observable,{
	LoginLogo:new Ext.Panel({
		id:'loginLogo',
		height:45,
		frame:true,
		bodyStyle:'padding-top:0px',
		html:'<div><p><img src="./images/bullet.gif">登录</p><div>'
	}),
	//login form
	LoginForm:new Ext.form.FormPanel({
		id:'loginForm',
		defaultType:'textfield',
		labelAlign:'right',
		labelWidth:60,
		frame:true,
		defaults:{
			allowBlank:false
		},
		items:[
		{id:'username',name:'user.userid',fieldLabel:'登录账号',blankText:'不能为空',emptyText:'必填',anchor:'98%'},
		{id:'password',name:'user.password',fieldLabel:'登录密码',blankText:'不能为空',inputType:'password',anchor:'98%',maxLength:10}
		]
		
	}),
	
	//login window
	LoginWin:new Ext.Window({
		id:'loginWin',
		Title:'登录入口',
		width:250,
		height:200,
		x:850,
		y:350,
		closable:true,
		collapsible:false,
		resizable:false,
		defaults:{
			border:false
		},
		buttonAlign:'center',
		buttons:[
		{text:'登录',type:'submit',id:'sb',height:100,handler:login},
		{text:'重置',height:100,handler:function(){
			Ext.getCmp('loginForm').form.reset();
		}}	
		],
		keys:[
		{key:Ext.EventObject.ENTER,fn:login,scope:this}
		],
		layout:'column',
		items:[
		{columnWidth:1,items:Ext.getCmp("loginLogo")},
		{columnWidth:1,items:Ext.getCmp("loginForm")}
		]
		}),
	init:function(){
		this.LoginWin.show();
	}
	
	
});

function login(){
	
	
	var loginForm = Ext.getCmp("loginForm");
	//valid load the process bar
	if(loginForm.form.isValid()){
		loginForm.form.submit({
			waitMsg:'正在进行验证，请稍后',
			url:'login/login.action',
			method:'POST',			
			//call back
			success:function(form,action){
				if(action.result.msg == 'OK'){
					window.location.href="index.html";
				}else if(action.result.msg == 'ERROR'){
					Ext.Msg.alert("登录失败");
					Ext.getCmp('loginForm').form.reset();
				}
			},
			failure:function(form,action){
				
				switch (action.failureType) {    
                            case Ext.form.Action.CLIENT_INVALID:    
                                Ext.Msg.alert('错误提示', '表单数据非法请核实后重新输入！');    
                                break;    
                            case Ext.form.Action.CONNECT_FAILURE:    
                                Ext.Msg.alert('错误提示', '网络连接异常！');    
                                break;    
                            case Ext.form.Action.SERVER_INVALID:    
                               Ext.Msg.alert('错误提示', "您的输入用户信息有误，请核实后重新输入！");    
                               simple.form.reset();      
                            }  
			}
		});
	}
}
